import zipfile
import datetime

# a set of information about a zip file
class ZipInfo():
    """zip info"""

    """constructor"""
    def __init__ (self, filename, datetime, filesize, compresssize):
        self.filename = filename
        self.datetime = datetime
        self.filesize = filesize
        self.compresssize = compresssize

# parses a zip file and get a list of ZipInfo
class ZipParser():
    """parses a zip file"""
    
    def __init__ (self, archivename):
        """constructor"""
        self.zipfile = zipfile.ZipFile(archivename, mode='a') # append
    
    def archiveinfo(self):
        """retrieves a list of info from member of the archive"""
        info_list = []
        for info in self.zipfile.infolist():
            zip_info = ZipInfo( info.filename, datetime.datetime(*info.date_time), info.file_size, info.compress_size)
            info_list.append(zip_info)
        return info_list
    
    def add(self, filename):
        """add a file to the archive"""
        self.zipfile.write(filename)

    def extract(self, filename, dest):
        """extract a file from the archive to a given dest"""
        self.zipfile.extract(filename, dest)

    def extractall(self, dest):
        """extract all files from the archive to a given dest"""
        self.zipfile.extractall(dest)

    def seefilecontent(self, filename):
        """read the file content"""
        content = self.zipfile.read(filename)
    
    def close(self):
        """closes the archive"""
        self.zipfile.close()

